<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionDispatch::Session::CacheStore</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActionDispatch::Session::CacheStore 
            
                <span class="parent">&lt; 
                    
                    <a href="AbstractStore.html">ActionDispatch::Session::AbstractStore</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_dispatch/middleware/session/cache_store_rb.html">actionpack/lib/action_dispatch/middleware/session/cache_store.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="../Session.html">Session</a> store that uses an <a
href="../../ActiveSupport/Cache/Store.html">ActiveSupport::Cache::Store</a>
to store the sessions. This store is most useful if you don't store
critical data in your sessions and you don't need them to live for extended
periods of time.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="CacheStore.html#method-i-destroy_session">destroy_session</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>G</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="CacheStore.html#method-i-get_session">get_session</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="CacheStore.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="CacheStore.html#method-i-set_session">set_session</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(app, options = {})
            
            <a href="CacheStore.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Create a new store. The cache to use can be passed in the
<code>:cache</code> option. If it is not specified,
<code>Rails.cache</code> will be used.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3fbc8f385bfd5e486cdbd4da6c1604f5c312770b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb#L11" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 11</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-ivar">@cache</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:cache</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">cache</span>
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:expire_after</span>] <span class="ruby-operator">||=</span> <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">options</span>[<span class="ruby-value">:expires_in</span>]
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-destroy_session">
            
              <b>destroy_session</b>(env, sid, options)
            
            <a href="CacheStore.html#method-i-destroy_session" name="method-i-destroy_session" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Remove a session from the cache.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-destroy_session_source')" id="l_method-i-destroy_session_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3fbc8f385bfd5e486cdbd4da6c1604f5c312770b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb#L37" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-destroy_session_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 37</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">destroy_session</span>(<span class="ruby-identifier">env</span>, <span class="ruby-identifier">sid</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">cache_key</span>(<span class="ruby-identifier">sid</span>))
  <span class="ruby-identifier">generate_sid</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-get_session">
            
              <b>get_session</b>(env, sid)
            
            <a href="CacheStore.html#method-i-get_session" name="method-i-get_session" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Get a session from the cache.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-get_session_source')" id="l_method-i-get_session_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3fbc8f385bfd5e486cdbd4da6c1604f5c312770b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb#L18" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-get_session_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 18</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">get_session</span>(<span class="ruby-identifier">env</span>, <span class="ruby-identifier">sid</span>)
  <span class="ruby-identifier">sid</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">generate_sid</span>
  <span class="ruby-identifier">session</span> = <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">cache_key</span>(<span class="ruby-identifier">sid</span>))
  <span class="ruby-identifier">session</span> <span class="ruby-operator">||=</span> {}
  [<span class="ruby-identifier">sid</span>, <span class="ruby-identifier">session</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-set_session">
            
              <b>set_session</b>(env, sid, session, options)
            
            <a href="CacheStore.html#method-i-set_session" name="method-i-set_session" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Set a session in the cache.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-set_session_source')" id="l_method-i-set_session_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/3fbc8f385bfd5e486cdbd4da6c1604f5c312770b/actionpack/lib/action_dispatch/middleware/session/cache_store.rb#L26" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-set_session_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_dispatch/middleware/session/cache_store.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">set_session</span>(<span class="ruby-identifier">env</span>, <span class="ruby-identifier">sid</span>, <span class="ruby-identifier">session</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">key</span> = <span class="ruby-identifier">cache_key</span>(<span class="ruby-identifier">sid</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">session</span>
    <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">session</span>, <span class="ruby-value">:expires_in</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:expire_after</span>])
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">sid</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    